In [7]:
import pandas as pd
import altair as alt
import geopandas as gpd
import json
In [8]:
f = pd.read_csv('../data/population_trends.csv')
df = f[f["year"] == 2019]
df.head()
Out[8]:
region year rate
30 Ukraine 2019 -6.6
61 Crimea 2019 NaN
92 Vinnytsya 2019 -7.9
123 Volyn 2019 -2.8
154 Dnipropetrovs'k 2019 -8.9
In [9]:
ukraine = gpd.read_file('../data/ukraine.json')
ukraine = ukraine[["NAME_1", "geometry"]]
ukraine.head()
Out[9]:
NAME_1 geometry
0 Cherkasy MULTIPOLYGON (((31.32614 48.74507, 31.31716 48...
1 Chernihiv MULTIPOLYGON (((33.09283 50.50966, 33.09261 50...
2 Chernivtsi MULTIPOLYGON (((24.93280 47.72794, 24.93301 47...
3 Crimea MULTIPOLYGON (((33.79291 44.39153, 33.79465 44...
4 Dnipropetrovs'k MULTIPOLYGON (((33.93176 47.48407, 33.92332 47...
In [10]:
plot1 = alt.Chart(ukraine).mark_geoshape().encode(
    color=alt.Color(field='rate', type='quantitative', scale=alt.Scale(scheme='redyellowgreen', reverse=True), legend=alt.Legend(title='Population growth/shrinkage ate', orient='left'))
).transform_lookup(
    lookup='NAME_1',
    from_=alt.LookupData(df, 'region', ['rate'])
)

df = f[f.region != 'Ukraine']

plot2 = alt.Chart(df).mark_line().encode(
    x = alt.X(field='year', type='nominal'),
    y = alt.Y(field='rate', type='quantitative'),
    detail = 'region:N',
)

alt.hconcat(plot1, plot2).properties(background = '#F9F9F9', padding = 25)
Out[10]: